tidyr::who %>%
pivot_longer(new_sp_m014:newrel_f65,
names_to = "key",
values_to = "tb_cases",
values_drop_na = TRUE) %>%
mutate(key = str_replace(key, "newrel", "new_rel")) %>%
separate(key, into = c("case_type", "tb_type", "sex_age")) %>%
separate(sex_age, into = c("sex", "age_group"), sep = 1) %>%
select(-case_type, -matches("iso"))
## # A tibble: 76,046 x 6
## country year tb_type sex age_group tb_cases
## <chr> <int> <chr> <chr> <chr> <int>
## 1 Afghanistan 1997 sp m 014 0
## 2 Afghanistan 1997 sp m 1524 10
## 3 Afghanistan 1997 sp m 2534 6
## 4 Afghanistan 1997 sp m 3544 3
## 5 Afghanistan 1997 sp m 4554 5
## 6 Afghanistan 1997 sp m 5564 2
## 7 Afghanistan 1997 sp m 65 0
## 8 Afghanistan 1997 sp f 014 5
## 9 Afghanistan 1997 sp f 1524 38
## 10 Afghanistan 1997 sp f 2534 36
## # ... with 76,036 more rows